package guoanmaker.operator.business.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.model.OperatorAdvertisingPush;
import guoanmaker.operator.business.model.OperatorAppBanner;
import guoanmaker.operator.business.model.OperatorBoutiqueRecommend;
import guoanmaker.operator.business.model.OperatorHeadline;
import guoanmaker.operator.business.model.OperatorHotBusinessNewForAPP;
import guoanmaker.operator.business.model.OperatorHotServer;
import guoanmaker.operator.business.model.OperatorHotwords;
import guoanmaker.operator.business.model.OperatorPromotionNew;
import guoanmaker.operator.business.model.OperatorRoundPhotoApp;
import guoanmaker.operator.business.model.OperatorServerClass;
import guoanmaker.operator.business.repository.OperatorAdvertisingPushRepository;
import guoanmaker.operator.business.repository.OperatorAppBannerRepository;
import guoanmaker.operator.business.repository.OperatorBoutiqueRecommendRepository;
import guoanmaker.operator.business.repository.OperatorHeadlineRepository;
import guoanmaker.operator.business.repository.OperatorHotBusinessNewForAPPRepository;
import guoanmaker.operator.business.repository.OperatorHotServerRepository;
import guoanmaker.operator.business.repository.OperatorHotwordsRepository;
import guoanmaker.operator.business.repository.OperatorPromotionNewRepository;
import guoanmaker.operator.business.repository.OperatorRoundPhotoAppRepository;
import guoanmaker.operator.business.repository.OperatorServerClassRepository;



@Service
public class OperatorGroundAppService implements OperatorGroundAppServiceInterface {
	@Autowired
	 private  OperatorRoundPhotoAppRepository OperatorRoundPhotoAppRepository;
	@Autowired
	private  OperatorHotwordsRepository operatorHotwordsRepository;
	@Autowired
	private  OperatorAppBannerRepository operatorAppBannerRepository;
	@Autowired
	private  OperatorHeadlineRepository operatorHeadlineRepository;
	@Autowired
	private OperatorBoutiqueRecommendRepository operatorBoutiqueRecommendRepository;
	@Autowired
	 private  OperatorHotServerRepository operatorHotServerRepository;
	@Autowired
	    private  OperatorServerClassRepository operatorServerClassRepository;
	@Autowired
	private OperatorPromotionNewRepository operatorPromotionNewRepository;
	@Autowired
	private OperatorHotBusinessNewForAPPRepository operatorHotBusinessNewForAPPRepository;
	@Autowired
	private OperatorAdvertisingPushRepository advertisingPushRepository;
	
	@Override
	public Map selectGroundApp(String cityId) {
		Map<String, Object> reMap = new HashMap<>();
		List<OperatorRoundPhotoApp>  rpspps=OperatorRoundPhotoAppRepository.findBycityCode(cityId);
		reMap.put("rpspps", rpspps);
		OperatorHotwords hot=operatorHotwordsRepository.findByCityCodeOne(cityId);
		 List<OperatorHotwords> hots= operatorHotwordsRepository.findByCityCodetwo(cityId);
		 reMap.put("hot", hot);
		 reMap.put("hots", hots);
		
		List<OperatorAppBanner> bans= operatorAppBannerRepository.findBycityCode(cityId);
	    	for(OperatorAppBanner ban:bans){
	    		
	    	if(ban.getIsHot()==1){
	    		ban.setFasehot(true);
	    	}else{
	    		ban.setFasehot(false);
	    	}
	    	if(ban.getIsNew()==1){
	    		ban.setFasenew(true);
	    	}else{
	    		ban.setFasenew(false);
	    	}
	    	if(ban.getItemLevel()!=null&&!ban.getItemLevel().equals("")){
	    	if(ban.getItemLevel()==1){
	    		ban.setCopyitemLevel("1");
	    	}else{
	    		ban.setCopyitemLevel("2");
	    	}
	    	}
	    	}
	    	reMap.put("bans", bans);
	    	
	    	List<OperatorHeadline> heads=operatorHeadlineRepository.findBycityCode(cityId);
	    	reMap.put("heads", heads);
	    	 List<OperatorHotServer> servers = operatorHotServerRepository.findBycityCode(cityId);
	         for(OperatorHotServer server:servers){
	         	 OperatorServerClass serverClass=	operatorServerClassRepository.findOne(server.getServerId());
	         	 server.setServerName(serverClass.getServerName());
	         }
	         reMap.put("hotservers", servers);
	    	List<OperatorBoutiqueRecommend> OperatorBoutiqueRecommends=operatorBoutiqueRecommendRepository.findByCityCodePc(cityId);
	    	reMap.put("OperatorBoutiqueRecommends", OperatorBoutiqueRecommends);
	    	List<OperatorPromotionNew> pronews=operatorPromotionNewRepository.selectByOperatorPromotionNew(cityId);
	    	reMap.put("pronews", pronews);
	    	List<OperatorHotBusinessNewForAPP> hotBusApp  = operatorHotBusinessNewForAPPRepository.findOperatorHotBusinessNewByCityCode(cityId);
	    	reMap.put("hotBusApp", hotBusApp);
	    	List<OperatorAdvertisingPush> advertisingPushs = advertisingPushRepository.findByCityId(cityId);
	    	if (advertisingPushs != null && advertisingPushs.size() >0) {
	    		reMap.put("advertisingPush", advertisingPushs.get(0));
	    	}else {
	    		reMap.put("advertisingPush", null);
	    	}
	    	
		return reMap;
	}

}
